package au.com.langdale.gwt.client.model;

import java.util.Iterator;
import java.util.Vector;

import au.com.langdale.gwt.client.remote.EditManager;

/**
 * A utility class managing a list of ModelListeners and 
 * fanning out events to them.
 * 
 * @author adv
 *
 */
public class ModelListenerCollection extends Vector {

	  /**
	   * Fires a change event to all listeners.
	   */
	  public void fireModelChange(Object model) {
	    for (Iterator it = iterator(); it.hasNext();) {
	      ModelListener listener = (ModelListener) it.next();
	      listener.onModelChange(model);
	    }
	  }

	  /**
	   * Fires a contents change event to all listeners.
	   */
	  public void fireContentsChange(Object container) {
	    for (Iterator it = iterator(); it.hasNext();) {
	      ModelListener listener = (ModelListener) it.next();
	      listener.onContentsChange(container);
	    }
	  }

	  /**
	   * Fires a contents change pending event to all listeners.
	   */
	  public void fireChange(Object container) {
	    for (Iterator it = iterator(); it.hasNext();) {
	      ModelListener listener = (ModelListener) it.next();
	      listener.onChange(container);
	    }
	  }

	public void fireCommit(Object container) {
	    for (Iterator it = iterator(); it.hasNext();) {
		      ModelListener listener = (ModelListener) it.next();
		      listener.onCommit(container);
	    }
	}
}
